home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / Process.h < prev    next >
C/C++ Source or Header  |  1990-05-19  |  4KB  |  124 lines

  1. #ifndef    PROCESS_H
  2. #define    PROCESS_H
  3.  
  4. /*$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Process.h,v 3.0 90/05/20 00:20:51 kgorlen Rel $*/
  5.  
  6. /* Process.h -- Declarations for lightweight processes
  7.  
  8.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  9.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  10.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  11.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  12.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  13.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  14.  
  15. Author:
  16.     K. E. Gorlen
  17.     Computer Systems Laboratory, DCRT
  18.     National Institutes of Health
  19.     Bethesda, MD 20892
  20.  
  21. $Log:    Process.h,v $
  22.  * Revision 3.0  90/05/20  00:20:51  kgorlen
  23.  * Release for 1st edition.
  24.  * 
  25. */
  26.  
  27. #include "Link.h"
  28. #include "String.h"
  29. #include "nihclconfig.h"
  30.  
  31. #ifdef HAVE_SELECT
  32. #include "FDSet.h"
  33. #endif
  34.  
  35. const int MAXPRIORITY = 7;    // maximum process priority
  36.  
  37. class Catch;
  38. class ExceptionActionTbl;
  39. class ExceptionEnv;
  40. class HeapProc;
  41. class Scheduler;
  42. class Semaphore;
  43. class StackProc;
  44.  
  45. #ifndef NESTED_TYPES
  46. typedef char* stackTy;
  47. #endif
  48.  
  49. class Process: public Link {
  50.     DECLARE_MEMBERS(Process);
  51. public:            // type definitions
  52. #ifdef NESTED_TYPES
  53.     typedef char* stackTy;
  54. #endif
  55.     enum processState { SUSPENDED, RUNNING, TERMINATED };
  56. public:            // static member functions
  57.     static void copyStack(const stackTy* src, stackTy* dst, unsigned long count);
  58.     static stackTy* topOfStack() {
  59.         auto stackTy top;
  60.         stackTy* temp = ⊤    // to avoid warning message
  61.         return temp;
  62.     }
  63. private:
  64.     String process_name;
  65.     processState process_state;    // SUSPENDED, RUNNING, or TERMINATED 
  66.     unsigned char process_priority;
  67.     ExceptionEnv* saved_exception_env_stack_top;
  68.     ExceptionActionTbl* saved_exception_action;
  69.     Catch* saved_catch_stack_top;
  70. protected:
  71. #ifdef HAVE_SELECT
  72.     FDSet rdmask, wrmask, exmask;    // masks for select(2)
  73. #endif
  74.     JMP_BUF env;            // environment save structure for setjmp/longjmp
  75.     stackTy* stack_bottom;        // pointer to stack bottom
  76.  
  77.     friend Scheduler;
  78.     friend Semaphore;
  79. protected:
  80.     Process(const char* name, stackTy* bottom, int priority =0);
  81.     Process(stackTy* bottom, int priority =0);    // MAIN Process constructor
  82.     Process(const Process&);            // shouldNotImplement()
  83.     unsigned& PC()        { return ENV_PC(env); }
  84.     unsigned PC() const    { return ENV_PC(env); }
  85.     unsigned& SP()        { return ENV_SP(env); }
  86.     unsigned SP() const    { return ENV_SP(env); }
  87.     unsigned& FP()        { return ENV_FP(env); }
  88.     unsigned FP() const    { return ENV_FP(env); }
  89.     void add();                    // add this process to Scheduler runlist
  90.     virtual    void deepenShallowCopy();        // shouldNotImplement()
  91.     virtual void restore();
  92.     virtual void save();
  93.     virtual void storer(OIOofd&) const;        // shouldNotImplement()
  94.     virtual void storer(OIOout&) const;        // shouldNotImplement()
  95.     virtual void switchContext(Process*) = 0;
  96. public:
  97.     ~Process();
  98.     const char* name() const    { return process_name; }
  99.     processState state() const    { return process_state; }
  100.  
  101. #ifdef HAVE_SELECT
  102.     virtual void select(FDSet&, FDSet&, FDSet&);    // add to select list
  103. #endif
  104.  
  105.     virtual unsigned capacity() const;        // returns stack size 
  106.     virtual int compare(const Object&) const;    // compare process priorities 
  107.     virtual void dumpOn(ostream& strm =cerr) const;
  108.     virtual unsigned hash() const;
  109.     virtual bool isEqual(const Object& ob) const;
  110.     virtual void printOn(ostream& strm =cout) const;
  111.     virtual unsigned char priority() const;
  112.     virtual unsigned char priority(unsigned char newPriority);
  113.     virtual void resume();
  114.     virtual    unsigned size() const = 0;
  115.     virtual void suspend();
  116.     virtual void switchFrom(HeapProc*) = 0;
  117.     virtual    void switchFrom(StackProc*) = 0;
  118.     virtual void terminate();
  119. private:                // shouldNotImplement()
  120.     virtual Object* copy() const;
  121. };
  122.  
  123. #endif
  124.